﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TI_4_Limonade_Fabriek.Database;
using TI_4_Limonade_Fabriek.Model;
using TI_4_Limonade_Fabriek.Logging;

namespace TI_4_Limonade_Fabriek.Views
{
    public partial class OperatorOverview : Form
    {
        BatchDBController bdbc;
        List<Batch> batchList;
        BatchLogging bl;
        ErrorLogging el;

        public OperatorOverview()
        {
            InitializeComponent();
            bdbc = new BatchDBController();
            batchList = new List<Batch>();
            bl = new BatchLogging();
            el = new ErrorLogging();
            FillBatchList();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void OperatorOverview_Load(object sender, EventArgs e)
        {
            BatchOverviewRefreshTimer.Start();
        }

        private void FillBatchList()
        {
            batchList.Clear();
            batchList = bdbc.ReadBatchList();

            dgvBatchLijst.DataSource = batchList;
            RenameColumnHeaders();
        }

        private void RenameColumnHeaders()
        {
            dgvBatchLijst.Columns[0].HeaderText = "Batch ID";
            dgvBatchLijst.Columns[2].HeaderText = "Aantal Bekers";
        }

        private void btnShowErrorLog_Click(object sender, EventArgs e)
        {
            el.ShowErrorLog();
        }

        private void btnShowBatchLog_Click(object sender, EventArgs e)
        {
            bl.ShowBatchLog();
        }

        private void BatchOverviewRefreshTimer_Tick(object sender, EventArgs e)
        {
            FillBatchList();
        }

        private void OperatorOverview_FormClosing(object sender, FormClosingEventArgs e)
        {
            BatchOverviewRefreshTimer.Stop();
        }
    }
}
